<template>
  <div class="find_renovation">
    <div class="your_name">
      <div>
        <input type="text" v-model="formData.name" placeholder="请输入您的姓名">
      </div>
    </div>
    <div class="your_tell">
      <div>
        <input type="number" v-model="formData.contact" placeholder="请输入您的联系方式">
      </div>
    </div>
    <!--<div class="your_area">-->
      <!--&lt;!&ndash;<div>请选择城市 <span class="iconfont icon-xiala"></span></div>&ndash;&gt;-->
      <!--<div @click="isAreaShow">{{locationName}} <span class="iconfont icon-xiala"></span></div>-->
    <!--</div>-->
    <!--<div class="your_tell">-->
      <!--<div>-->
        <!--<input type="text" v-model="formData.quarter" placeholder="请输入小区名称">-->
      <!--</div>-->
    <!--</div>-->
    <div class="your_submit">
      <div @click="yourSubmit">
        提交
      </div>
    </div>
    <div  v-if="areaShow" @touchmove="handelTouchMove">
      <area-simulation-two  :areaList="areaList" :closeSelect="closeSelect" v-if="areaShow"></area-simulation-two>
    </div>
  </div>
</template>

<script>
  import {customerData,indexAreaList} from '../../axios/api';
  import {getCityName} from '../../assets/js/cache';
  import AreaSimulationTwo from './AreaSimulationTwo';
  import { MessageBox } from 'mint-ui';
  export default {
    name: 'FindRenovation',
    components: {AreaSimulationTwo},
    data() {
      return {
        areaList:[],
        formData: {
          name:'',
          contact:'',
          city:getCityName().CODE,
          // area:'',
          // quarter:'',
          type:1
        },
        cityShow:false,
        areaShow:false,
        locationName:'请选择区域'
      }
    },
    watch:{
      areaList(curVal, oldVal){
        this.setLocationName();
      },
      getArea(curVal, oldVal) {
        this.setLocationName();
      },
    },
    computed:{
      getFindTitle(){
        return this.$store.getters.getFindTitle;
      },
      getArea(){
        return this.$store.getters.getAreaTitle;
      }
    },
    methods:{
      //选择区域
      isAreaShow(){
        document.getElementsByTagName('body')[0].style.overflow = 'hidden';
        indexAreaList(getCityName().CODE).then(res=>{
          console.log(getCityName().CODE,'areaList');
          this.areaList = res.data;
          console.log(this.areaList);
          this.areaShow = true;
        }).catch(err=>{
          console.log(err)
        });

      },
      setLocationName() {
        let b = this.areaList.filter((item) => {
          return item.value === this.getArea;
        });
        console.log(b);
        if (b.length) {
          this.locationName = b[0].label;
          //label
        }
      },
      //提交
      yourSubmit(){
        let that = this;
        console.log(that.getFindTitle);
        console.log(getCityName());
        that.formData.city = getCityName().CODE;
        that.formData.type = that.getFindTitle;
        // that.formData.area = that.getArea;
        customerData(that.formData).then(res=>{
        document.getElementsByTagName('body')[0].style.overflow = 'auto';
          if (res.data.code === 1) {
            // 成功
            MessageBox.alert(res.data.msg).then(action => {
              console.log(action);
              that.formData = {};
              that.$store.commit('clearAreaTitle');
              that.locationName = '请选择区域';
            });
          }
          else {
            //错误\
            MessageBox.alert(res.data.msg).then(action => {
              console.log(action)
            });
          }
          console.log(res);
          console.log(that.formData);
        }).catch(err=>{
          console.log(err);
        })
      },
      //关闭模态框
      closeSelect(){
        this.cityShow = false;
        this.areaShow = false;
        document.getElementsByTagName('body')[0].style.overflow = 'auto';
      },
      //阻止事件冒泡
      handelTouchMove(e){
        e.preventDefault();
      }
    },
  }
</script>

<style scoped>
  .find_renovation>div {
    margin:0 10px;
  }

  .find_renovation > div {
    height: 40px;
    line-height: 40px;
  }

  .find_renovation .your_name {
    display: flex;
    font-size: 0.9rem;
    color: #999999;
    justify-content: space-between;
  }

  .find_renovation .your_name input {
    /*height: 1.2rem;*/
    outline: 0;
    border: none;
  }

  .find_renovation .your_tell {
    display: flex;
    font-size: 0.9rem;
    color: #999999;
    justify-content: space-between;
    border-top: 1px solid #eeeeee;
  }

  .find_renovation .your_tell input {
    /*height: 1.2rem;*/
    outline: 0;
    border: none;

  }

  .find_renovation .your_area {
    display: flex;
    font-size: 0.9rem;
    color: #999999;
    /*justify-content: space-between;*/
    border-top: 1px solid #eeeeee;
  }

  .find_renovation .your_area > div {
    width: 50%;
  }
  .find_renovation .your_submit{
    margin: 0;
    background-color: #f8f8f8;
    color: white;
    border-top: 1px solid #eeeeee;
    border-bottom: 1px solid #eeeeee;
    padding: 10px;
  }
  .find_renovation .your_submit>div{
    background-color: #e6191e;
    text-align: center;
  }
</style>
